package com.bw.day03.change

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.net.mvvm.BaseActivity
import com.bw.day03.R
import com.bw.day03.databinding.ActivityChangeBinding

class ChangeActivity : BaseActivity<ActivityChangeBinding,ChangeViewModel>() {
    override fun initView() {
        binding.getCode.setOnClickListener {
            viewModel.sendCode(SPUtils.getInstance().getString("phone"))
        }
        binding.change.setOnClickListener {
            val code=binding.code.text.toString()
            val password=binding.password.text.toString()
            viewModel.change(SPUtils.getInstance().getString("phone"),code,password)
        }

    }

    override fun initData() {
        viewModel.sendSuccess.observe(this){
            if (it.code==200){
                binding.code.setText(it.data.content.substring(8,14))
            }
        }
        viewModel.success.observe(this){
            if (it.code==200){
                ToastUtils.showLong("修改成功")
            }
        }

    }

    override fun getViewModel(): Class<ChangeViewModel> = ChangeViewModel::class.java

    override fun getLayoutId(): Int =  R.layout.activity_change
}